<template>
    <form class="form fcbc">
        <f-type @select="e_select" />
        <f-coin @select="e_select" />
        <f-way @select="e_select" />
        <f-price @input="e_input" />
        <f-count @input="e_input" />
        <f-msg :msg="msg" />
         <!-- <f-connect @input="e_input" />  -->
        <f-password @input="e_input" />
        <hb-button class="btn"
            v-bind:txt="Lang.from[lang][1]"
            @clk="e_submit" />
        <hb-dialog v-if="finalmsg !== ''"
            @clk="e_en()">
            <span v-text="finalmsg"/>
        </hb-dialog>
    </form>
</template>

<script>
let check = form => {
	let re = true
	for (const key in form) {
		if (form.hasOwnProperty(key)) {
			const value = form[key]
			if (value == null) {
				re = false
			}
		}
	}
	return re
}
import Ftype from './f-type'
import Fcoin from './f-coin'
import Fway from './f-way'
import Fprice from './f-price'
import Fcount from './f-count'
import Fmsg from './f-msg'
import Fconnect from './f-connect'
import Fpassword from './f-password'
import {vpost, vlink} from '@api'
import Lang from './lang.js'
export default {
	name: 'cform',
	data() {
		return {
			Lang,
			form: {
				type:'', // 类型[string]
				coin: '', // 币种[string]
				way:[], // 支付方式[array]
				price: '', // 单价[string]
				count:'', // 总量[string]
				//connect: null, // 联系方式[string]
				password: '', // 交易密码[string]
			},
			msg: [], // 向msg组件传入手续费
			finalmsg: '',
		}
	},
	computed: {
		lang() {
			return this.$store.state.setting.lang
		},
	},
	components: {
		'f-type': Ftype,
		'f-coin': Fcoin,
		'f-way': Fway,
		'f-price': Fprice,
		'f-count': Fcount,
		'f-msg': Fmsg,
		//'f-connect': Fconnect,
		'f-password': Fpassword,
	},
	created() {},
	methods: {
		e_select(which, v) {
			this.form[which] = v
			let {price, count,type} = this.form
			if (price != null && count != null) {
				this.msg = [price, count,type]
			}
		},
		e_input(which, v) {
			this.form[which] = v
			let {price, count,type} = this.form
			if (price != null && count != null) {
				this.msg = [price, count,type]
			}
		},
		e_submit() {
			//if (!check(this.form)) {
			//	this.finalmsg = '您的表单未填写完整'
			//	return false
			//}
			if (this.$limitTimer()) {
				return
			}
			// if (this.form.price === null || this.form.count === null||this.form.way===null||this.form.password===null) {
			// 	this.finalmsg = '您的表单未填写完整'
			// 	return false
			// }
			this.api_send()
		},
		api_send() {
			let paymode='';
			for(let i in this.form.way){
				paymode=paymode+this.form.way[i]+','
			}
			let dataInput={
				 fid:this.$store.state.user.uid,
 				 type:this.form.type,
 				 price:this.form.price,
 				 count:this.form.count,
 				 coinType:this.form.coin,
 				 payMethods:paymode,
 				 password:this.form.password,
			}
			
			vpost(vlink.ddd.releaseAdvert,dataInput).then(re => {
				this.form.password=''
				this.finalmsg=re.msg
				setTimeout(() => {
				this.finalmsg = ''
			}, 1300)
			})
		},
		e_en() {
			this.finalmsg = ''
		},
	},
}
</script>

<style scoped>
.form {
	margin: 0 auto;
	border-radius: 6px;
	box-shadow: 0 0 5px rgb(80, 78, 78);
	padding: 40px 0;
	width: 600px;
}
</style>